package com.icode.core.shared;

import com.icode.core.model.house.HouseBaseArea;
import com.icode.core.model.house.HouseBaseTheme;
import com.icode.core.model.house.ProductType;
import org.springframework.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-6-11
 * Time: 下午4:08
 * To change this template use File | Settings | File Templates.
 */
public class HouseBaseHandle {


    public static String initAreaHql(String area) {
        String hql = "";
        if (!com.icode.core.shared.StringUtils.isEmpty(area)) {
            HouseBaseArea houseBaseArea = HouseBaseArea.valueOf(area);
            hql = " and a.houseBaseArea='" + houseBaseArea + "'";
        }
        return hql;
    }

    public static String initPriceHql(String price) {
        int min;
        int max;
        String hql = "";
        if (!StringUtils.isEmpty(price)) {
            String[] split = price.split("-");
            min = Integer.valueOf(split[0]);
            max = Integer.valueOf(split[1]);
            hql = " and ( a.price between " + min * 10000 + " and " + max * 10000 + " )";
        } else {

        }
        return hql;
    }

    public static String initThemeHql(String theme) {
        String hql = "";
        if (!StringUtils.isEmpty(theme)) {
            hql = " and a.themes like '%" + theme + "%'";
        }
        return hql;
    }

    public static String initProductType(String productType) {
        String hql = "";
        if(!productType.equals("all")&&!productType.equals("APARTMENT")&&!productType.equals("HOUSEBASE")){
            productType="all";
        }
        if (productType.equals("all") || StringUtils.isEmpty(productType)) {
            hql = " and (a.productType ='APARTMENT' or a.productType='HOUSEBASE')";
        } else {
            hql = " and a.productType='" + ProductType.valueOf(productType)+"'";
        }
        return hql;
    }
}
